/**
 * Created by xwang on 2018-09-12.
 */
var request = require("superagent");
var API = require("./support/const");
// var service = require("../../service/log");

/**
 * 新闻与通知
 * **/
exports.news = {
    list: function (req, res, next) {
        let header = {
            token: req.cookies.token
        };
        let params = req.body;
        request.get(API.news.list)
            .set(header)
            .query({msg: JSON.stringify(params)})
            .end(function (_req, _res) {
                res.json(JSON.parse(_res.text));
            });
    },
    detail: function (req, res, next) {
        let header = {
            token: req.cookies.token
        };
        let params = req.body;
        let {id} = req.body;
        request.get(API.news.detail + id)
            .set(header)
            .query({id: id})
            .end(function (_req, _res) {
                res.json(JSON.parse(_res.text));
            });
    },

    add: function (req, res, next) {
        let header = {
            token: req.cookies.token
        };
        console.log( req.body)
        let params = req.body;
        request.post(API.news.add)
            .set(header)
            .query({msg: JSON.stringify(params)})
            .end(function (_req, _res) {
                res.json(JSON.parse(_res.text));
            });
    },

    update: function (req, res, next) {
        let header = {
            token: req.cookies.token
        };
        let params = req.body;
        request.put(API.news.update)
            .set(header)
            .query({msg: JSON.stringify(params)})
            .end(function (_req, _res) {
                res.json(JSON.parse(_res.text));
            });
    },

    publish: function (req, res, next) {
        let header = {
            token: req.cookies.token
        };
        let params = req.body;
        let {id} = req.body;
        request.put(API.news.publish + id)
            .set(header)
            .end(function (_req, _res) {
                res.json(JSON.parse(_res.text));
            });
    },

    cancel: function (req, res, next) {
        let header = {
            token: req.cookies.token
        };
        let params = req.body;
        let {id} = req.body;
        request.put(API.news.cancel + id)
            .set(header)
            .end(function (_req, _res) {
                res.json(JSON.parse(_res.text));
            });
    },

    delete: function (req, res, next) {
        let header = {
            token: req.cookies.token
        };
        let params = req.body;
        let {id} = req.body;
        request.put(API.news.delete + id)
            .set(header)
            .end(function (_req, _res) {
                res.json(JSON.parse(_res.text));
            });
    },

};
